package com.zengqingfa.rocketmq.consumer;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Service;

/**
 *
 * @fileName: MqDemo01Consumer
 * @author: zengqf3
 * @date: 2021-4-2 22:36
 * @description:
 * starter 2.0.3有bug,selectorExpression 表达式不生效
 * 参考：https://blog.csdn.net/xiaojun081004/article/details/104954802
 */
@Slf4j
@Service
@RocketMQMessageListener(topic = "${rocketmq.topic.demo01}", consumerGroup = "${rocketmq.consumerGroup.demo01}", selectorExpression = "${rocketmq.tag.demo01}")
public class MqDemo01Consumer implements RocketMQListener<MessageExt> {

    @Override
    public void onMessage(MessageExt message) {
        log.info("消费消息开始：{}", JSON.toJSONString(message));
        log.info("topic:{}", message.getTopic());
        log.info("tages:{}", message.getTags());
        log.info("msgId:{}", message.getMsgId());
        log.info("body:{}", new String(message.getBody()));
    }
}
